package com.cdy.jxc_project.controller;

import com.cdy.jxc_project.json.R;
import com.cdy.jxc_project.mapper.TPurchaseListMapper;
import com.cdy.jxc_project.mapper.TSaleListMapper;
import com.cdy.jxc_project.utils.GetSevenDate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/*
 * @Project:jxc_project
 * @Author:cdy(缘生)
 * @Motto:放下杂念,只为迎接明天更好的自己
 * @Date:2023/5/8 14:37
 * */

@RestController
@RequestMapping("/echarts")
public class EchartsController {

    @Resource
    private TPurchaseListMapper tPurchaseListMapper;

    @Resource
    private TSaleListMapper tSaleListMapper;

    @PostMapping("/week")
    public R queryWeekData() {
        List<String> sevenDates = GetSevenDate.getSevenDate();
        List<Integer> purMoneys = new ArrayList<>();
        for (String oneDay : sevenDates) {
            Integer purchaseMoney = tPurchaseListMapper.getPurchaseMoney(oneDay);
            purMoneys.add(purchaseMoney == null ? 0 : purchaseMoney);
            System.out.println(oneDay + "进货费用:" + purchaseMoney);
        }
//获取销售的价格
        List<Integer> saleMoneys = new ArrayList<>();
        for (String oneDay : sevenDates) {
            Integer purchaseMoney = tSaleListMapper.daySaleList(oneDay);
            saleMoneys.add(purchaseMoney == null ? 0 : purchaseMoney);
            System.out.println(oneDay + "进货费用:" + saleMoneys);
        }
        return R.ok().message("查询成功").data("days", sevenDates).
                data("purchaseData", purMoneys).
                data("saleData", saleMoneys);
    }

}

